const router=require('koa-router')();
const koaBody=require('koa-body');

router.get('/',async ctx=>{

    console.log('myFalsh:',ctx.myFlash);
    await ctx.render('post',{
        name:'Post',
        success:ctx.myFlash.success,
        error:ctx.myFlash.error
    });
});


router.post('/',koaBody(),async ctx=>{
    let {body}=ctx.request;
    if(body.title&&body.content){
        ctx.myFlash={success:'发表成功'};
    }else{
        ctx.myFlash={error:'未输入标题或内容'};
    }
    ctx.redirect('back');
});
module.exports=router;